package frame.options.simulation.results.virtualNetworks.numerical;

import java.text.DecimalFormat;
import java.util.Iterator;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import model.components.links.link.BandwidthBackupFlag;
import model.components.links.link.VirtualLink;
import model.components.networks.network.VirtualNetwork;
import model.components.nodes.node.Node;
import model.components.nodes.node.VirtualNode;
import model.components.nodes.node.VirtualRouter;
import model.components.nodes.node.PhysicalRouter;
import model.components.nodes.node.VirtualServer;
import model.components.nodes.node.PhysicalServer;
import model.components.nodes.node.VirtualSwitch;
import model.components.nodes.node.PhysicalSwitch;

@SuppressWarnings("serial")
public class VirtualNetworkTable extends JTable
{
	private VirtualNetwork virtualNetwork;
	public VirtualNetwork getVirtualNetwork(){ return virtualNetwork; }
	public void setVirtualNetwork( VirtualNetwork virtualNetwork ){ this.virtualNetwork = virtualNetwork; }
	
	public VirtualNetworkTable( VirtualNetwork virtualNetwork )
	{	
		this.setVirtualNetwork( virtualNetwork );
		
		this.setModel( this.model() );
		this.setEnabled( false );
	}
	
	private DefaultTableModel model()
	{
		DefaultTableModel defaultTableModel = new DefaultTableModel( new String[]{ "<html><b>RESOURCES</b></html>", "<html><b>VIRTUAL</b></html>", "<html><b>PHYSICAL</b></html>", "<html><b>ALLOCATION</b></html>" }, 0 );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>LINKS</b></html>" } );
		
		if( this.numberVlanRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "VLANs number", (int) this.numberVlanRequest(), (int) this.numberVlanSubstrate(), new DecimalFormat( "0.00" ).format( this.numberVlanAverage() ) } );

		if( this.numberSonetRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "PDH/SONets number", (int) this.numberSonetRequest(), (int) this.numberSonetSubstrate(), new DecimalFormat( "0.00" ).format( this.numberSonetAverage() ) } );

		if( this.number80211Request() > 0 )
			defaultTableModel.addRow( new Object[]{ "802.11s number", (int) this.number80211Request(), (int) this.number80211Substrate(), new DecimalFormat( "0.00" ).format( this.number80211Average() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Bandwidth</b></html>" } );
		
		if( this.bandwidthVlanRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "VLANs bandwidth", (int) this.bandwidthVlanRequest(), (int) this.bandwidthVlanSubstrate(), new DecimalFormat( "0.00" ).format( this.bandwidthVlanAverage() ) } );

		if( this.bandwidthSonetRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "PDH/SONets bandwidth", (int) this.bandwidthSonetRequest(), (int) this.bandwidthSonetSubstrate(), new DecimalFormat( "0.00" ).format( this.bandwidthSonetAverage() ) } );
		
		if( this.bandwidth80211Request() > 0 )
			defaultTableModel.addRow( new Object[]{ "802.11s bandwidth", (int) this.bandwidth80211Request(), (int) this.bandwidth80211Substrate(), new DecimalFormat( "0.00" ).format( this.bandwidth80211Average() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>NODES</b></html>" } );
		
		if( this.numberRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Number Routers", (int) this.numberRoutersRequest(), (int) this.numberRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.numberRoutersAverage() ) } );
		
		if( this.numberSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Number Switches", (int) this.numberSwitchesRequest(), (int) this.numberSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.numberSwitchesAverage() ) } );
		
		if( this.numberServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Number Servers", (int) this.numberServersRequest(), (int) this.numberServersSubstrate(), new DecimalFormat( "0.00" ).format( this.numberServersAverage() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Operating System</b></html>" } );
		
		if( this.linuxRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Linux Routers", (int) this.linuxRoutersRequest(), (int) this.linuxRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.linuxRoutersAverage() ) } );
		
		if( this.linuxSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Linux Switches", (int) this.linuxSwitchesRequest(), (int) this.linuxSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.linuxSwitchesAverage() ) } );
		
		if( this.linuxServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Linux Servers", (int) this.linuxServersRequest(), (int) this.linuxServersSubstrate(), new DecimalFormat( "0.00" ).format( this.linuxServersAverage() ) } );
		
		if( this.windowsRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Windows Routers", (int) this.windowsRoutersRequest(), (int) this.windowsRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.windowsRoutersAverage() ) } );
		
		if( this.windowsSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Windows Switches", (int) this.windowsSwitchesRequest(), (int) this.windowsSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.windowsSwitchesAverage() ) } );
		
		if( this.windowsServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Windows Servers", (int) this.windowsServersRequest(), (int) this.windowsServersSubstrate(), new DecimalFormat( "0.00" ).format( this.windowsServersAverage() ) } );
		
		if( this.solarisRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Solaris Routers", (int) this.solarisRoutersRequest(), (int) this.solarisRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.solarisRoutersAverage() ) } );
		
		if( this.solarisSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Solaris Switches", (int) this.solarisSwitchesRequest(), (int) this.solarisSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.solarisSwitchesAverage() ) } );
		
		if( this.solarisServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Solaris Servers", (int) this.solarisServersRequest(), (int) this.solarisServersSubstrate(), new DecimalFormat( "0.00" ).format( this.solarisServersAverage() ) } );
		
		if( this.androidRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Android Routers", (int) this.androidRoutersRequest(), (int) this.androidRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.androidRoutersAverage() ) } );
		
		if( this.androidSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Android Switches", (int) this.androidSwitchesRequest(), (int) this.androidSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.androidSwitchesAverage() ) } );
		
		if( this.androidServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Android Servers", (int) this.androidServersRequest(), (int) this.androidServersSubstrate(), new DecimalFormat( "0.00" ).format( this.androidServersAverage() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Virtual environment</b></html>" } );
		
		if( this.vmwareRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "VMWare Routers", (int) this.vmwareRoutersRequest(), (int) this.vmwareRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.vmwareRoutersAverage() ) } );
		
		if( this.vmwareSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "VMWare Switches", (int) this.vmwareSwitchesRequest(), (int) this.vmwareSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.vmwareSwitchesAverage() ) } );
		
		if( this.vmwareServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "VMWare Servers", (int) this.vmwareServersRequest(), (int) this.vmwareServersSubstrate(), new DecimalFormat( "0.00" ).format( this.vmwareServersAverage() ) } );
						
		if( this.xenRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Xen Routers", (int) this.xenRoutersRequest(), (int) this.xenRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.xenRoutersAverage() ) } );
		
		if( this.xenSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Xen Switches", (int) this.xenSwitchesRequest(), (int) this.xenSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.xenSwitchesAverage() ) } );
		
		if( this.xenServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Xen Servers", (int) this.xenServersRequest(), (int) this.xenServersSubstrate(), new DecimalFormat( "0.00" ).format( this.xenServersAverage() ) } );
		
		if( this.kvmRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "KVM Routers", (int) this.kvmRoutersRequest(), (int) this.kvmRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.kvmRoutersAverage() ) } );
		
		if( this.kvmSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "KVM Switches", (int) this.kvmSwitchesRequest(), (int) this.kvmSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.kvmSwitchesAverage() ) } );
		
		if( this.kvmServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "KVM Servers", (int) this.kvmServersRequest(), (int) this.kvmServersSubstrate(), new DecimalFormat( "0.00" ).format( this.kvmServersAverage() ) } );
		
		if( this.umlRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "UML Routers", (int) this.umlRoutersRequest(), (int) this.umlRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.umlRoutersAverage() ) } );
		
		if( this.umlSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "UML Switches", (int) this.umlSwitchesRequest(), (int) this.umlSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.umlSwitchesAverage() ) } );
		
		if( this.umlServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "UML Servers", (int) this.umlServersRequest(), (int) this.umlServersSubstrate(), new DecimalFormat( "0.00" ).format( this.umlServersAverage() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>CPU</b></html>" } );
		
		if( this.cpuRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "CPU Routers", (int) this.cpuRoutersRequest(), (int) this.cpuRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.cpuRoutersAverage() ) } );
		
		if( this.cpuSwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "CPU Switches", (int) this.cpuSwitchesRequest(), (int) this.cpuSwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.cpuSwitchesAverage() ) } );
		
		if( this.cpuServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "CPU Servers", (int) this.cpuServersRequest(), (int) this.cpuServersSubstrate(), new DecimalFormat( "0.00" ).format( this.cpuServersAverage() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Memory</b></html>" } );
		
		if( this.memoryRoutersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Memory Routers", (int) this.memoryRoutersRequest(), (int) this.memoryRoutersSubstrate(), new DecimalFormat( "0.00" ).format( this.memoryRoutersAverage() ) } );
		
		if( this.memorySwitchesRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Memory Switches", (int) this.memorySwitchesRequest(), (int) this.memorySwitchesSubstrate(), new DecimalFormat( "0.00" ).format( this.memorySwitchesAverage() ) } );
		
		if( this.memoryServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Memory Servers", (int) this.memoryServersRequest(), (int) this.memoryServersSubstrate(), new DecimalFormat( "0.00" ).format( this.memoryServersAverage() ) } );
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Disk Space</b></html>" } );
		
		if( this.diskSpaceServersRequest() > 0 )
			defaultTableModel.addRow( new Object[]{ "Disk Space Servers", (int) this.diskSpaceServersRequest(), (int) this.diskSpaceServersSubstrate(), new DecimalFormat( "0.00" ).format( this.diskSpaceServersAverage() ) } );
		
		return defaultTableModel;
	}
	
	private double numberVlanRequest()
	{
		double numberVlanRequest = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.VLAN_TYPE ) )
				numberVlanRequest++;
		
		return numberVlanRequest;
	}
	private double numberVlanSubstrate()
	{
		double numberVlanSubstrate = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.VLAN_TYPE ) )
				numberVlanSubstrate += linkRequest.getPhysicalLinksBandwidthsBackupFlags().size();
		
		return numberVlanSubstrate;
	}
	private double numberVlanAverage()
	{
		if( this.numberVlanRequest() == 0 )
			return 0;
		
		return this.numberVlanSubstrate() / this.numberVlanRequest();
	}
	
	private double numberSonetRequest()
	{
		double numberSonetRequest = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.SONET_TYPE ) )
				numberSonetRequest++;
		
		return numberSonetRequest;
	}
	private double numberSonetSubstrate()
	{
		double numberSonetSubstrate = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.SONET_TYPE ) )
				numberSonetSubstrate += linkRequest.getPhysicalLinksBandwidthsBackupFlags().size();
		
		return numberSonetSubstrate;
	}
	private double numberSonetAverage()
	{
		if( this.numberSonetRequest() == 0 )
			return 0;
		
		return this.numberSonetSubstrate() / this.numberSonetRequest();
	}
	
	private double number80211Request()
	{
		double number80211Request = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.EIGHT0211_TYPE ) )
				number80211Request++;
		
		return number80211Request;
	}
	private double number80211Substrate()
	{
		double number80211Substrate = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.EIGHT0211_TYPE ) )
				number80211Substrate += linkRequest.getPhysicalLinksBandwidthsBackupFlags().size();
		
		return number80211Substrate;
	}
	private double number80211Average()
	{
		if( this.number80211Request() == 0 )
			return 0;
		
		return this.number80211Substrate() / this.number80211Request();
	}
	
	private double bandwidthVlanRequest()
	{
		double bandwidthVlanRequest = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.VLAN_TYPE ) )
				bandwidthVlanRequest += linkRequest.getBandwidth();
		
		return bandwidthVlanRequest;
	}
	private double bandwidthVlanSubstrate()
	{
		double bandwidthVlanSubstrate = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.VLAN_TYPE ) )
			{
				Iterator< BandwidthBackupFlag > iterator = linkRequest.getPhysicalLinksBandwidthsBackupFlags().values().iterator();
			
				while( iterator.hasNext() )
					bandwidthVlanSubstrate += iterator.next().getBandwidth();
			}
		
		return bandwidthVlanSubstrate;
	}
	private double bandwidthVlanAverage()
	{
		if( this.bandwidthVlanRequest() == 0 )
			return 0;
		
		return this.bandwidthVlanSubstrate() / this.bandwidthVlanRequest();
	}
	
	private double bandwidthSonetRequest()
	{
		double bandwidthSonetRequest = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.SONET_TYPE ) )
				bandwidthSonetRequest += linkRequest.getBandwidth();
		
		return bandwidthSonetRequest;
	}
	private double bandwidthSonetSubstrate()
	{
		double bandwidthSonetSubstrate = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.SONET_TYPE ) )
			{
				Iterator< BandwidthBackupFlag > iterator = linkRequest.getPhysicalLinksBandwidthsBackupFlags().values().iterator();
			
				while( iterator.hasNext() )
					bandwidthSonetSubstrate += iterator.next().getBandwidth();
			}
		
		return bandwidthSonetSubstrate;
	}
	private double bandwidthSonetAverage()
	{
		if( this.bandwidthSonetRequest() == 0 )
			return 0;
		
		return this.bandwidthSonetSubstrate() / this.bandwidthSonetRequest();
	}
	
	private double bandwidth80211Request()
	{
		double bandwidth80211Request = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.EIGHT0211_TYPE ) )
				bandwidth80211Request += linkRequest.getBandwidth();
		
		return bandwidth80211Request;
	}
	private double bandwidth80211Substrate()
	{
		double bandwidth80211Substrate = 0;
		
		for( VirtualLink linkRequest: this.getVirtualNetwork().getVirtualLinks() )
			if( linkRequest.getType().equals( VirtualLink.EIGHT0211_TYPE ) )
			{
				Iterator< BandwidthBackupFlag > iterator = linkRequest.getPhysicalLinksBandwidthsBackupFlags().values().iterator();
			
				while( iterator.hasNext() )
					bandwidth80211Substrate += iterator.next().getBandwidth();
			}
		
		return bandwidth80211Substrate;
	}
	private double bandwidth80211Average()
	{
		if( this.bandwidth80211Request() == 0 )
			return 0;
		
		return this.bandwidth80211Substrate() / this.bandwidth80211Request();
	}
	
	private double numberRoutersRequest()
	{
		double numberRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				numberRoutersRequest++;
		
		return numberRoutersRequest;
			
	}
	private double numberRoutersSubstrate()
	{
		double numberRoutersSubstrate = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest.getPhysicalNode() != null )
				if( nodeRequest.getPhysicalNode() instanceof PhysicalRouter )
					numberRoutersSubstrate++;
			
		return numberRoutersSubstrate;
	}
	private double numberRoutersAverage()
	{
		if( this.numberRoutersRequest() == 0 )
			return 0;
		
		return this.numberRoutersSubstrate() / this.numberRoutersRequest();
	}
	
	private double numberSwitchesRequest()
	{
		double numberSwitchesRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				numberSwitchesRequest++;
		
		return numberSwitchesRequest;
	}
	private double numberSwitchesSubstrate()
	{
		double numberSwitchesSubstrate = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest.getPhysicalNode() != null )
				if( nodeRequest.getPhysicalNode() instanceof PhysicalSwitch )
					numberSwitchesSubstrate++;
			
		return numberSwitchesSubstrate;
	}
	private double numberSwitchesAverage()
	{
		if( this.numberSwitchesRequest() == 0 )
			return 0;
		
		return this.numberSwitchesSubstrate() / this.numberSwitchesRequest();
	}
	
	private double numberServersRequest()
	{
		double numberServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				numberServersRequest++;
		
		return numberServersRequest;
	}
	private double numberServersSubstrate()
	{
		double numberServersSubstrate = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest.getPhysicalNode() != null )
				if( nodeRequest.getPhysicalNode() instanceof PhysicalServer )
					numberServersSubstrate++;
			
		return numberServersSubstrate;
	}
	private double numberServersAverage()
	{
		if( this.numberServersRequest() == 0 )
			return 0;
		
		return this.numberServersSubstrate() / this.numberServersRequest();
	}
	
	private double linuxRoutersRequest()
	{
		double linuxRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getOperatingSystem().equals( Node.LINUX_OS ) )
					linuxRoutersRequest++;
		
		return linuxRoutersRequest;
	}
	private double linuxRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.linuxRoutersRequest();
	}
	private double linuxRoutersAverage()
	{
		if( this.linuxRoutersRequest() == 0 )
			return 0;
		
		return this.linuxRoutersSubstrate() / this.linuxRoutersRequest();
	}
	
	private double linuxSwitchesRequest()
	{
		double linuxSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getOperatingSystem().equals( Node.LINUX_OS ) )
					linuxSwitchsRequest++;
		
		return linuxSwitchsRequest;
	}
	private double linuxSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.linuxSwitchesRequest();
	}
	private double linuxSwitchesAverage()
	{
		if( this.linuxSwitchesRequest() == 0 )
			return 0;
		
		return this.linuxSwitchesSubstrate() / this.linuxSwitchesRequest();
	}

	private double linuxServersRequest()
	{
		double linuxServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getOperatingSystem().equals( Node.LINUX_OS ) )
					linuxServersRequest++;
		
		return linuxServersRequest;
	}
	private double linuxServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.linuxServersRequest();
	}
	private double linuxServersAverage()
	{
		if( this.linuxServersRequest() == 0 )
			return 0;
		
		return this.linuxServersSubstrate() / this.linuxServersRequest();
	}

	private double windowsRoutersRequest()
	{
		double windowsRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getOperatingSystem().equals( Node.WINDOWS_OS ) )
					windowsRoutersRequest++;
		
		return windowsRoutersRequest;
	}
	private double windowsRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.windowsRoutersRequest();
	}
	private double windowsRoutersAverage()
	{
		if( this.windowsRoutersRequest() == 0 )
			return 0;
		
		return this.windowsRoutersSubstrate() / this.windowsRoutersRequest();
	}
	
	private double windowsSwitchesRequest()
	{
		double windowsSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getOperatingSystem().equals( Node.WINDOWS_OS ) )
					windowsSwitchsRequest++;
		
		return windowsSwitchsRequest;
	}
	private double windowsSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.windowsSwitchesRequest();
	}
	private double windowsSwitchesAverage()
	{
		if( this.windowsSwitchesRequest() == 0 )
			return 0;
		
		return this.windowsSwitchesSubstrate() / this.windowsSwitchesRequest();
	}

	private double windowsServersRequest()
	{
		double windowsServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getOperatingSystem().equals( Node.WINDOWS_OS ) )
					windowsServersRequest++;
		
		return windowsServersRequest;
	}
	private double windowsServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.windowsServersRequest();
	}
	private double windowsServersAverage()
	{
		if( this.windowsServersRequest() == 0 )
			return 0;
		
		return this.windowsServersSubstrate() / this.windowsServersRequest();
	}
	
	private double solarisRoutersRequest()
	{
		double solarisRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getOperatingSystem().equals( Node.SOLARIS_OS ) )
					solarisRoutersRequest++;
		
		return solarisRoutersRequest;
	}
	private double solarisRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.solarisRoutersRequest();
	}
	private double solarisRoutersAverage()
	{
		if( this.solarisRoutersRequest() == 0 )
			return 0;
		
		return this.solarisRoutersSubstrate() / this.solarisRoutersRequest();
	}
	
	private double solarisSwitchesRequest()
	{
		double solarisSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getOperatingSystem().equals( Node.SOLARIS_OS ) )
					solarisSwitchsRequest++;
		
		return solarisSwitchsRequest;
	}
	private double solarisSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.solarisSwitchesRequest();
	}
	private double solarisSwitchesAverage()
	{
		if( this.solarisSwitchesRequest() == 0 )
			return 0;
		
		return this.solarisSwitchesSubstrate() / this.solarisSwitchesRequest();
	}

	private double solarisServersRequest()
	{
		double solarisServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getOperatingSystem().equals( Node.SOLARIS_OS ) )
					solarisServersRequest++;
		
		return solarisServersRequest;
	}
	private double solarisServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.solarisServersRequest();
	}
	private double solarisServersAverage()
	{
		if( this.solarisServersRequest() == 0 )
			return 0;
		
		return this.solarisServersSubstrate() / this.solarisServersRequest();
	}
	
	private double androidRoutersRequest()
	{
		double androidRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getOperatingSystem().equals( Node.ANDROID_OS ) )
					androidRoutersRequest++;
		
		return androidRoutersRequest;
	}
	private double androidRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.androidRoutersRequest();
	}
	private double androidRoutersAverage()
	{
		if( this.androidRoutersRequest() == 0 )
			return 0;
		
		return this.androidRoutersSubstrate() / this.androidRoutersRequest();
	}
	
	private double androidSwitchesRequest()
	{
		double androidSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getOperatingSystem().equals( Node.ANDROID_OS ) )
					androidSwitchsRequest++;
		
		return androidSwitchsRequest;
	}
	private double androidSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.androidSwitchesRequest();
	}
	private double androidSwitchesAverage()
	{
		if( this.androidSwitchesRequest() == 0 )
			return 0;
		
		return this.androidSwitchesSubstrate() / this.androidSwitchesRequest();
	}

	private double androidServersRequest()
	{
		double androidServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getOperatingSystem().equals( Node.ANDROID_OS ) )
					androidServersRequest++;
		
		return androidServersRequest;
	}
	private double androidServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.androidServersRequest();
	}
	private double androidServersAverage()
	{
		if( this.androidServersRequest() == 0 )
			return 0;
		
		return this.androidServersSubstrate() / this.androidServersRequest();
	}
	
	private double vmwareRoutersRequest()
	{
		double vmwareRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getVirtualEnvironment().equals( Node.VMWARE_VE ) )
					vmwareRoutersRequest++;
		
		return vmwareRoutersRequest;
	}
	private double vmwareRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.vmwareRoutersRequest();
	}
	private double vmwareRoutersAverage()
	{
		if( this.vmwareRoutersRequest() == 0 )
			return 0;
		
		return this.vmwareRoutersSubstrate() / this.vmwareRoutersRequest();
	}
	
	private double vmwareSwitchesRequest()
	{
		double vmwareSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getVirtualEnvironment().equals( Node.VMWARE_VE ) )
					vmwareSwitchsRequest++;
		
		return vmwareSwitchsRequest;
	}
	private double vmwareSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.vmwareSwitchesRequest();
	}
	private double vmwareSwitchesAverage()
	{
		if( this.vmwareSwitchesRequest() == 0 )
			return 0;
		
		return this.vmwareSwitchesSubstrate() / this.vmwareSwitchesRequest();
	}

	private double vmwareServersRequest()
	{
		double vmwareServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getVirtualEnvironment().equals( Node.VMWARE_VE ) )
					vmwareServersRequest++;
		
		return vmwareServersRequest;
	}
	private double vmwareServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.vmwareServersRequest();
	}
	private double vmwareServersAverage()
	{
		if( this.vmwareServersRequest() == 0 )
			return 0;
		
		return this.vmwareServersSubstrate() / this.vmwareServersRequest();
	}
	
	private double xenRoutersRequest()
	{
		double xenRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getVirtualEnvironment().equals( Node.XEN_VE ) )
					xenRoutersRequest++;
		
		return xenRoutersRequest;
	}
	private double xenRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.xenRoutersRequest();
	}
	private double xenRoutersAverage()
	{
		if( this.xenRoutersRequest() == 0 )
			return 0;
		
		return this.xenRoutersSubstrate() / this.xenRoutersRequest();
	}
	
	private double xenSwitchesRequest()
	{
		double xenSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getVirtualEnvironment().equals( Node.XEN_VE ) )
					xenSwitchsRequest++;
		
		return xenSwitchsRequest;
	}
	private double xenSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.xenSwitchesRequest();
	}
	private double xenSwitchesAverage()
	{
		if( this.xenSwitchesRequest() == 0 )
			return 0;
		
		return this.xenSwitchesSubstrate() / this.xenSwitchesRequest();
	}

	private double xenServersRequest()
	{
		double xenServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getVirtualEnvironment().equals( Node.XEN_VE ) )
					xenServersRequest++;
		
		return xenServersRequest;
	}
	private double xenServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.xenServersRequest();
	}
	private double xenServersAverage()
	{
		if( this.xenServersRequest() == 0 )
			return 0;
		
		return this.xenServersSubstrate() / this.xenServersRequest();
	}
	
	private double kvmRoutersRequest()
	{
		double kvmRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getVirtualEnvironment().equals( Node.KVM_VE ) )
					kvmRoutersRequest++;
		
		return kvmRoutersRequest;
	}
	private double kvmRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.kvmRoutersRequest();
	}
	private double kvmRoutersAverage()
	{
		if( this.kvmRoutersRequest() == 0 )
			return 0;
		
		return this.kvmRoutersSubstrate() / this.kvmRoutersRequest();
	}
	
	private double kvmSwitchesRequest()
	{
		double kvmSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getVirtualEnvironment().equals( Node.KVM_VE ) )
					kvmSwitchsRequest++;
		
		return kvmSwitchsRequest;
	}
	private double kvmSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.kvmSwitchesRequest();
	}
	private double kvmSwitchesAverage()
	{
		if( this.kvmSwitchesRequest() == 0 )
			return 0;
		
		return this.kvmSwitchesSubstrate() / this.kvmSwitchesRequest();
	}

	private double kvmServersRequest()
	{
		double kvmServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getVirtualEnvironment().equals( Node.KVM_VE ) )
					kvmServersRequest++;
		
		return kvmServersRequest;
	}
	private double kvmServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.kvmServersRequest();
	}
	private double kvmServersAverage()
	{
		if( this.kvmServersRequest() == 0 )
			return 0;
		
		return this.kvmServersSubstrate() / this.kvmServersRequest();
	}
	
	private double umlRoutersRequest()
	{
		double umlRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				if( nodeRequest.getVirtualEnvironment().equals( Node.UML_VE ) )
					umlRoutersRequest++;
		
		return umlRoutersRequest;
	}
	private double umlRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.umlRoutersRequest();
	}
	private double umlRoutersAverage()
	{
		if( this.umlRoutersRequest() == 0 )
			return 0;
		
		return this.umlRoutersSubstrate() / this.umlRoutersRequest();
	}
	
	private double umlSwitchesRequest()
	{
		double umlSwitchsRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				if( nodeRequest.getVirtualEnvironment().equals( Node.UML_VE ) )
					umlSwitchsRequest++;
		
		return umlSwitchsRequest;
	}
	private double umlSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.umlSwitchesRequest();
	}
	private double umlSwitchesAverage()
	{
		if( this.umlSwitchesRequest() == 0 )
			return 0;
		
		return this.umlSwitchesSubstrate() / this.umlSwitchesRequest();
	}

	private double umlServersRequest()
	{
		double umlServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				if( nodeRequest.getVirtualEnvironment().equals( Node.UML_VE ) )
					umlServersRequest++;
		
		return umlServersRequest;
	}
	private double umlServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
			
		return this.umlServersRequest();
	}
	private double umlServersAverage()
	{
		if( this.umlServersRequest() == 0 )
			return 0;
		
		return this.umlServersSubstrate() / this.umlServersRequest();
	}
	
	private double cpuRoutersRequest()
	{
		double cpuRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				cpuRoutersRequest += nodeRequest.getCpu();
		
		return cpuRoutersRequest;
	}
	private double cpuRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.cpuRoutersRequest();
	}
	private double cpuRoutersAverage()
	{
		if( this.cpuRoutersRequest() == 0 )
			return 0;
		
		return this.cpuRoutersSubstrate() / this.cpuRoutersRequest();
	}
	
	private double cpuSwitchesRequest()
	{
		double cpuSwitchesRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				cpuSwitchesRequest += nodeRequest.getCpu();
		
		return cpuSwitchesRequest;
	}
	private double cpuSwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.cpuSwitchesRequest();
	}
	private double cpuSwitchesAverage()
	{
		if( this.cpuSwitchesRequest() == 0 )
			return 0;
		
		return this.cpuSwitchesSubstrate() / this.cpuSwitchesRequest();
	}
	
	private double cpuServersRequest()
	{
		double cpuServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				cpuServersRequest += nodeRequest.getCpu();
		
		return cpuServersRequest;
	}
	private double cpuServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.cpuServersRequest();
	}
	private double cpuServersAverage()
	{
		if( this.cpuServersRequest() == 0 )
			return 0;
		
		return this.cpuServersSubstrate() / this.cpuServersRequest();
	}
	
	private double memoryRoutersRequest()
	{
		double memoryRoutersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualRouter )
				memoryRoutersRequest += nodeRequest.getMemory();
		
		return memoryRoutersRequest;
	}
	private double memoryRoutersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.memoryRoutersRequest();
	}
	private double memoryRoutersAverage()
	{
		if( this.memoryRoutersRequest() == 0 )
			return 0;
		
		return this.memoryRoutersSubstrate() / this.memoryRoutersRequest();
	}
	
	private double memorySwitchesRequest()
	{
		double memorySwitchesRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualSwitch )
				memorySwitchesRequest += nodeRequest.getMemory();
		
		return memorySwitchesRequest;
	}
	private double memorySwitchesSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.memorySwitchesRequest();
	}
	private double memorySwitchesAverage()
	{
		if( this.memorySwitchesRequest() == 0 )
			return 0;
		
		return this.memorySwitchesSubstrate() / this.memorySwitchesRequest();
	}
	
	private double memoryServersRequest()
	{
		double memoryServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				memoryServersRequest += nodeRequest.getMemory();
		
		return memoryServersRequest;
	}
	private double memoryServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.memoryServersRequest();
	}
	private double memoryServersAverage()
	{
		if( this.memoryServersRequest() == 0 )
			return 0;
		
		return this.memoryServersSubstrate() / this.memoryServersRequest();
	}
	
	private double diskSpaceServersRequest()
	{
		double diskSpaceServersRequest = 0;
		
		for( VirtualNode nodeRequest: this.getVirtualNetwork().getVirtualNodes() )
			if( nodeRequest instanceof VirtualServer )
				diskSpaceServersRequest += nodeRequest.getDiskSpace();
		
		return diskSpaceServersRequest;
	}
	private double diskSpaceServersSubstrate()
	{
		if( this.getVirtualNetwork().getVirtualNodes().get( 0 ).getPhysicalNode() == null )
			return 0;
		
		return this.diskSpaceServersRequest();
	}
	private double diskSpaceServersAverage()
	{
		if( this.diskSpaceServersRequest() == 0 )
			return 0;
		
		return this.diskSpaceServersSubstrate() / this.diskSpaceServersRequest();
	}
	
}
